package mvc.controller.filter;

import mvc.model.pojos.AddressBean;
import mvc.model.pojos.OrderBean;
import mvc.model.pojos.ProductBean;
import mvc.model.pojos.UserBean;
import mvc.model.service.AddressService;
import mvc.model.service.OrderService;
import mvc.model.service.ProductService;
import mvc.model.service.impl.AddressServiceImpl;
import mvc.model.service.impl.OrderServiceImpl;
import mvc.model.service.impl.ProductServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

@WebFilter(filterName = "OrderFilter", urlPatterns = "/myOrder.jsp")

public class OrderFilter implements Filter {
    private static AddressService addressService;
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        UserBean userBean = (UserBean) request.getSession().getAttribute("user");
        List<AddressBean> select = addressService.select(userBean.getUid(), 1);
        request.getSession().setAttribute("addrList", select);
        System.out.println("order");

        //查询订单

        chain.doFilter(request, response);
    }

    public void init(FilterConfig config) throws ServletException {
        addressService = new AddressServiceImpl();
    }

}
